package com.cts.c2;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ActionBar;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
import android.support.v4.view.Window;
import android.support.v4.view.MenuItem.OnMenuItemClickListener;

public class CweetPostActivity extends FragmentActivity {
	private static final int SHOW_STREAM = 1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_ACTION_BAR_ITEM_TEXT);
		setContentView(R.layout.cweetit);

		// Action bar
		ActionBar bar = getSupportActionBar();
		bar.setDisplayHomeAsUpEnabled(true);
		// bar.addTab(bar.newTab().setIcon(R.drawable.ic_action_mark));
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		menu.add("Post").setIcon(R.drawable.ic_action_mark)
				.setOnMenuItemClickListener(postmenuItemClickListener)
				.setShowAsAction(
						MenuItem.SHOW_AS_ACTION_ALWAYS
								| MenuItem.SHOW_AS_ACTION_WITH_TEXT);

		return super.onCreateOptionsMenu(menu);
	}

	private OnMenuItemClickListener postmenuItemClickListener = new OnMenuItemClickListener() {

		@Override
		public boolean onMenuItemClick(MenuItem item) {
			Intent myIntent = new Intent();
			myIntent.setClassName("com.cts.c2", "com.cts.c2.StreamActivity");
			startActivityForResult(myIntent, SHOW_STREAM);
			return true;
		}

	};

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// app icon in Action Bar clicked; go home
			Intent intent = new Intent(this, StreamActivity.class);
			intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}
}
